//
// Created by hjie on 23-6-22.
//

#pragma once

#include <string>
#include <memory>
#include <uWS/uWS.h>

struct Connection
{
    uWS::WebSocket<uWS::SERVER> * m_socket;
    int64_t m_expire_time;
};

class WebSocket
{
public:
    WebSocket();
    virtual ~WebSocket();
    virtual int StartListen(int port);
    void StopServer();
    void ProcessSocketMap();
protected:
    uWS::Hub m_hub;
    bool m_status;
protected:
    std::map<int, Connection> m_connection_socket_map;
    int64_t m_count_timer{0};
};

class WebSocketServer : public WebSocket
{
public:
    WebSocketServer();
    virtual ~WebSocketServer();
    virtual int StartListen(int port) override;
};

class SSLWebSocketServer : public WebSocket
{
public:
    SSLWebSocketServer();
    virtual ~SSLWebSocketServer();
    virtual int StartListen(int port);
};

